//
//  Label.swift
//  GreenDeal
//
//  Created by Moennig Q on 9/12/2022.
//

import UIKit
import RxSwift
import RxCocoa
class BaseLabel: UILabel {
    private lazy var disposeBag = DisposeBag()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        //监听字体变化
        Constant.standardViewFlagSuject.subscribe { [weak self] _ in
            guard let strongSelf = self else {return}
            strongSelf.setRealFontSize(strongSelf.font)
        }.disposed(by: self.disposeBag)
    }
    //MARK: - 正常设置font
    func setFont(_ font: UIFont?) {
        if let font = font {
            if Constant.standardViewFlag {
                self.font = font
            }else{
                self.font = font.withSize(font.pointSize * Constant.magnifiedViewScale)
            }
            
        }
    }
    //MARK: - 设置真正的size
    private func setRealFontSize(_ font: UIFont?){
        if let font = font {
            self.font = font.withSize(font.pointSize * Constant.currentSizeScale)
        }
        
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
class ContentLabel: BaseLabel {
    init(_ font: UIFont? = R.font.interMedium(size: 14), text: String = "",  hexStr: String = "#292D32FF") {
        super.init(frame: CGRect.zero)
        self.initView(font, content: text, hexStr: hexStr)
        
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func initView(_ font: UIFont?, content: String = "",hexStr: String) {
        self.setFont(font)
        self.adjustsFontForContentSizeCategory = true
        self.textColor = UIColor(hexStr: hexStr)
        self.text = content
    }
}

